Inside Macintosh: Imaging with QuickDraw

Previous | Chapter Top | Chapter Contents | Next

Determining the Characteristics of a Video Device

For drawing images that are optimized for every screen they cross, your application can use the DeviceLoop procedure. The DeviceLoop procedure searches for graphics devices that intersect your window's drawing region, and it calls your drawing procedure for each different video device it finds. The DeviceLoop procedure provides your drawing procedure with information about the current device's pixel depth and other attributes.

To determine whether the flag bit for an attribute has been set in the gdFlags field of a GDevice record, your application can use the TestDeviceAttribute function.

To determine whether a video device supports a specific pixel depth, your application can also use the HasDepth function, described on HasDepth . To change the pixel depth of a video device, your application can use the SetDepth function, described on SetDepth .

If you need to determine the resolution of the main device, you can use the ScreenRes procedure.

DeviceLoop

For drawing images that are optimized for every screen they cross, use the DeviceLoop procedure.

PROCEDURE DeviceLoop (drawingRgn: RgnHandle;
                                         drawingProc: DeviceLoopDrawingProcPtr;
                                         userData: LongInt; flags: DeviceLoopFlags);
drawingRgn
A handle to the region in which you will draw; this drawing region uses coordinates that are local to its graphics port.
drawingProc
A pointer to your own drawing procedure.
userData
Any additional data that you wish to supply to your drawing procedure.
flags
One or more members of the set of flags defined by the DeviceLoopFlags data type:
             TYPE
                 DeviceLoopFlags = SET OF
                 (singleDevices,dontMatchSeeds,allDevices);
These flags are described in the following text; if you want to use the default behavior of DeviceLoop , specify an empty set ([]) in this parameter.

DESCRIPTION

The DeviceLoop procedure searches for graphics devices that intersect your window's drawing region, and it calls your drawing procedure for each video device it finds. In the  drawingRgn parameter, supply a handle to the region in which you wish to draw; in the drawingProc parameter, supply a pointer to your drawing procedure. In the flags parameter, you can specify members of the set of these flags defined by the DeviceLoopFlags data type:

singleDevices

If this flag is not set, DeviceLoop calls your drawing procedure only once for each set of similar graphics devices, and the first one found is passed as the target device. (It is assumed to be representative of all the similar graphics devices.) If you set the singleDevices flag, then DeviceLoop does not group similar graphics devices--that is, those having identical pixel depths, black-and-white or color settings, and matching color table seeds--when it calls your drawing procedure.

dontMatchSeeds

If you set the dontMatchSeeds flag, then DeviceLoop doesn't consider the ctSeed field of ColorTable records for graphics devices when comparing them; DeviceLoop ignores this flag if you set the singleDevices flag.

allDevices

If you set the allDevices flag, DeviceLoop ignores the drawingRgn parameter and calls your drawing procedure for every device. The value of current graphics port's visRgn field is not affected when you set this flag.

For each dissimilar video device that intersects this region, DeviceLoop calls your drawing procedure. For example, after a call to the Event Manager procedure BeginUpdate , the region you specify in the drawingRgn parameter can be the same as the visible region for the active window. Because DeviceLoop provides your drawing procedure with the pixel depth and other attributes of each video device, your drawing procedure can optimize its drawing for each video device--for example, by using the HiliteColor procedure to set magenta as the highlight color on a color video device.

SPECIAL CONSIDERATIONS

The DeviceLoop procedure may move or purge memory blocks in the application heap. Your application should not call this procedure at interrupt time.

SEE ALSO

Listing 1 illustrates the use of DeviceLoop . See Application-Defined Routine for a description of the drawing procedure you must provide for the drawingProc parameter. Offscreen graphics worlds are described in the next chapter. The HiliteColor procedure is described in the chapter "Color QuickDraw" in this book.

TestDeviceAttribute

To determine whether the flag bit for an attribute has been set in the gdFlags field of a GDevice record, use the TestDeviceAttribute function.

FUNCTION TestDeviceAttribute (gdh: GDHandle;
                                         attribute: Integer): Boolean;
gdh
A handle to a GDevice record.
attribute
One of the following constants, which represent bits in the gdFlags field of a GDevice record:
             CONST {flag bits for gdFlags field of GDevice record}
                gdDevType           = 0;    {if bit is set to 0, graphics }
                                            { device is black and white; }
                                            { if set to 1, device supports }
                                            { color}
                burstDevice         = 7;    {if bit is set to 1, device }
                                            { supports block transfer}
                ext32Device         = 8;    {if bit is set to 1, device }
                                            { must be used in 32-bit mode}
                ramInit             = 10;   {if bit is set to 1, device has }
                                            { been initialized from RAM}
                mainScreen          = 11;   {if bit is set to 1, device is }
                                            { the main screen}
                allInit             = 12;   {if bit is set to 1, all }
                                            { devices were initialized from }
                                            { 'scrn' resource}
                screenDevice        = 13;   {if bit is set to 1, device is }
                                            { a screen}
                noDriver            = 14;   {if bit is set to 1, GDevice }
                                            { record has no driver}
                screenActive        = 15;   {if bit is set to 1, device is }
                                            { active}

DESCRIPTION

The TestDeviceAttribute function tests a single graphics device attribute to see if its bit is set to 1 and, if so, returns TRUE . Otherwise, TestDeviceAttribute returns FALSE .

SPECIAL CONSIDERATIONS

The TestDeviceAttribute function may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.

SEE ALSO

Listing 3 illustrates the use of TestDeviceAttribute . Your application can use the SetDeviceAttribute procedure, described on SetDeviceAttribute , to change any of the flags tested by the TestDeviceAttribute function.

ScreenRes

If you need to determine the resolution of the main device, you can use the ScreenRes procedure.

PROCEDURE ScreenRes (VAR scrnHRes,scrnVRes: Integer);

DESCRIPTION

In the scrnHRes parameter, the ScreenRes procedure returns the number of horizontal pixels per inch displayed by the current device. In the scrnVRes parameter, it returns the number of vertical pixels per inch.

To determine the resolutions of all available graphics devices, you should examine their GDevice records (described on GDevice ). The horizontal and vertical resolutions for a graphics device are stored in the hRes and vRes fields, respectively, of the PixMap record for the device's GDevice record.

SPECIAL CONSIDERATIONS

Currently, QuickDraw and the Printing Manager always assume a screen resolution of 72 dpi.

Do not use the actual screen resolution as a scaling factor when drawing into a printing graphics port; instead, always use 72 dpi as the scaling factor. See the chapter "Printing Manager" in this book for more information about the Printing Manager and drawing into a printing graphics port.

ASSEMBLY-LANGUAGE INFORMATION

The horizontal resolution, in pixels per inch, is stored in the global variable ScrHRes , and the vertical resolution is stored in the global variable ScrVRes .


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next